/**
 * @Description:
 * @Author:       dingyi
 * @Date: 2021-11-03 20:33:03
 * @LastEditors:  zhengxu
 * @LastEditTime: 2021-11-11 15:06:27
 */
import { createRouter, createWebHashHistory } from 'vue-router'

// 自动获取platform文件夹下的js文件，动态获取路由配置
const modulesFiles1 = import.meta.globEager('./platform/*')
let keys = Object.keys(modulesFiles1)
let routerObj = []
const menuList = []
keys.forEach((key) => {
  const module = modulesFiles1[key]
  const mv = module.default
  const { group } = module
  if (group) {
    group.children = mv
    menuList.push(group)
  } else {
    menuList.push(mv)
  }
  if (mv instanceof Array) {
    routerObj = routerObj.concat(mv)
  } else {
    routerObj.push(mv)
  }
})
// 路由对象
const routes = [{
  path: '/',
  redirect: '/home'
}, {
  path: '/home',
  redirect: '/home/car',
  name: 'home',
  component: () => import('@/views/home/Home.vue'),
  children: routerObj
}]
const Router = createRouter({
  history: createWebHashHistory(),
  routes
})
menuList.sort((v1, v2) => v1.sort - v2.sort)
export { menuList }
export default Router
